<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Picture extends Model
{
    /**
     * 表名称
     * @var $table ;
     */
    protected $table = 'picture';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'id';


    /**
     * 时间戳   禁止
     * @var bool $timestamps
     */
    public $timestamps = false;


    protected $appends = array('url');


    /**
     * 自动填充字段
     * @var $fillable
     */

    protected $fillable = ['id', 'file_path', 'file_name', 'file_size','file_ext','file_mime_type'];


    function getUrlAttribute(){

        if ($this->getAttribute('server_url')!=''){
            $serverUrl = $this->getAttribute('server_url');
        }else{
            $serverUrl = config('oss.CdnHost');
        }

        return $serverUrl.'/'.$this->getAttribute('file_path');

    }

}
